package homework.homework_1;

public class Computer {
    private int computerNum = 0;

    public synchronized void production(){
        while(this.computerNum == 10){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        computerNum++;
        System.out.println("生产线程"
                + Thread.currentThread().getName()
                + "生产了一台电脑，当前电脑数量为："
                + computerNum);
        this.notify();
    }

    public synchronized void remove(){
        while(this.computerNum == 0){
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        computerNum--;
        System.out.println("搬运线程"
                + Thread.currentThread().getName()
                + "搬运了一台电脑，当前电脑数量为："
                + computerNum);
        this.notify();
    }
}
